﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using SprentCMS.Core.Models.ViewDatas;

namespace SprentCMS.Web.UI {
   public static  class ModuleExtension {
       public static string Module(this HtmlHelper h, string moduleName) {
           if (!(h.ViewData.Model is IBaseModuleViewData)) {
               return "";
           }
           IBaseModuleViewData vd = h.ViewData.Model as IBaseModuleViewData;
           string result = null;
           if (vd.Modules.ContainsKey(moduleName)) {
               foreach (var module in vd.Modules[moduleName]) {
                   if (string.IsNullOrEmpty(module.ModuleType)) {
                       continue;
                   }
                   result += module.BeginHTML + h.Partial("Modules/" + module.ModuleType, module).ToString() + module.EndHtml;
               }
           }
           return result;
       }
    }
}
